package org.raymond.iworks.study.redis.lettuce;

/*
import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.async.RedisAsyncCommands;
import io.lettuce.core.api.reactive.RedisReactiveCommands;
import io.lettuce.core.api.sync.RedisCommands;
 */
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutionException;

/**
 * @author raymond
 * @version V1.0
 * @Description: TODO
 */
@Slf4j
public class SyncCommandTask {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //test1();
    }

    /*
    private static void test1() throws ExecutionException, InterruptedException {
        RedisClient client = client();
        StatefulRedisConnection<String, String> connection = client.connect();
        // 同步
        RedisCommands<String, String> syncCommand = connection.sync();
        log.info("sync set hello1");
        syncCommand.set("hello1", "123");
        log.info("sync set hello2");
        syncCommand.set("hello2", "1234");

        // 异步
        RedisAsyncCommands<String, String> asyncCommands = connection.async();
        log.info("async set hello3");
        asyncCommands.set("hello3", "123");
        log.info("async set hello4");
        asyncCommands.set("hello4", "1234");

        // 响应式
        RedisReactiveCommands<String, String> reactiveCommands = connection.reactive();
        log.info("reactive set hello5");
        reactiveCommands.set("hello5", "hello5_123").subscribe();
        log.info("reactive set hello6");
        reactiveCommands.set("hello6", "hello6_123").subscribe();

        log.info("hello1: {}", syncCommand.get("hello1"));
        log.info("hello2: {}", syncCommand.get("hello2"));
        log.info("hello3: {}", asyncCommands.get("hello3").get());
        log.info("hello4: {}", asyncCommands.get("hello4").get());
        //log.info("hello5: {}", reactiveCommands.get("hello5").block());
        //log.info("hello6: {}", reactiveCommands.get("hello6").block());

        //reactiveCommands.get("hello5").subscribe(v->log.info("Got V {}", v));
        Flux.just("hello5", "hello6").flatMap(reactiveCommands::get).subscribe(v->log.info("get {}", v));

        // By default, a single Redis string can be a maximum of 512 MB.
        String oldval = syncCommand.getset("count", "1"); // 返回旧值
        // syncCommand.mset();
        //syncCommand.incr("count");
        //syncCommand.get("count");

        connection.close();
        client.shutdown();
    }

    private static RedisClient client(){
        RedisURI redisUri = RedisURI.builder()
                .withSsl(false)
                .withHost("192.168.0.125")
                .withPort(6379)
                .build();
        RedisClient redisClient = RedisClient.create(redisUri);
        return redisClient;
    }
     */
}
